package com.android.examplelist;

import android.app.ActionBar;
import android.app.Activity;
import android.app.ActionBar.OnNavigationListener;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

public class CustomActionBarActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.custom_actionbar);

		ActionBar actionBar = getActionBar();
		actionBar.setDisplayHomeAsUpEnabled(true);
		
		
		actionBar.setDisplayShowCustomEnabled(true);
		actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
		actionBar.setCustomView(R.layout.actionbar_title);
		
		
		
		/*
		// 获得图片资源
		BitmapDrawable bg_bar = (BitmapDrawable) getResources().getDrawable(R.drawable.ic_launcher);
		// 设置重复方向
		bg_bar.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
		// 设置背景图
		actionBar.setSplitBackgroundDrawable(bg_bar);
		
		BitmapDrawable bg = (BitmapDrawable) getResources().getDrawable(
				                      R.drawable.ic_launcher);
		bg.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
		//actionBar.setBackgroundDrawable(bg);
		*/

		
		TextView tvTitle = (TextView) getActionBar().getCustomView().findViewById(
				android.R.id.title);

		ImageButton ibtnNav = (ImageButton) getActionBar().getCustomView()
				.findViewById(R.id.left_btn);

		ibtnNav.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}

		});
		

	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			finish();
			return true;
		case R.id.action_settings:
			return true;
		}

		return super.onOptionsItemSelected(item);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
